﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using DbAdapter.sqldbAdapter;
using System.Data;

namespace DAO.WaiGaoQiao
{
    /// <summary>
    /// 规则领用规则
    /// </summary>
    public class DataAccessWork_ArticleRule
    {
        /// <summary>
        /// 根据id获取劳资规则对象
        /// </summary>
        /// <returns></returns>
        public DataSet GetWork_ArticleRuleById(int Id)
        {
            sqldb db = new sqldb();
            string query = "select ID,ArticleName,Month,Remark from ArticleRule where 1=1 and Id = " + Id;
            return db.ExecuteDataset(GetConntionString.conntionstring(), CommandType.Text, query);
        }


        /// <summary>
        /// 根据条件获取所有劳资规则。
        /// </summary>
        /// <returns></returns>
        public DataSet GetAllWork_ArticleRule(string condition)
        {
            sqldb db = new sqldb();
            string query = "select  ID,ArticleName,Month,Remark from ArticleRule where 1=1 " + condition;
            return db.ExecuteDataset(GetConntionString.conntionstring(), CommandType.Text, query);
        }

        /// <summary>
        /// 获取所有劳资规则(分页）
        /// </summary>
        /// <returns></returns>
        public DataSet GetAllWork_ArticleRule(string Condition, int pagesize, int startindex)
        {
            using (SqlConnection conn = new SqlConnection(GetConntionString.conntionstring()))
            {
                sqldb db = new sqldb();
                int startrow = pagesize * (startindex - 1);
                int endrow = pagesize * startindex + 1;
                string query = "select B.ID,B.ArticleName,B.Month,Remark from (select ROW_NUMBER() OVER(ORDER BY A.ID DESC) rownumber,"
                             + "A.ID,A.ArticleName,A.Month,A.Remark from ArticleRule A where 1=1 " + Condition + ") B "
                             + "where B.rownumber > " + startrow.ToString() + " and B.rownumber < " + endrow.ToString();
                return db.ExecuteDataset(conn, CommandType.Text, query);
            }
        }

        /// <summary>
        /// 保存或修改食材类型
        /// </summary>
        /// <param name="dmpara"></param>
        /// <returns></returns>
        public int SaveWork_ArticleRule(object[] ArticleType)
        {
            using (SqlConnection conn = new SqlConnection(GetConntionString.conntionstring()))
            {
                sqldb db = new sqldb();
                return db.ExecuteNonQuery(conn, "Proc_Work_ArticleRule", ArticleType);
            }
        }


        /// <summary>
        /// 删除物品规则
        /// </summary>
        /// <param name="did"></param>
        /// <returns></returns>
        public int DeleteWork_ArticleRule(string id)
        {
            sqldb db = new sqldb();
            string query = "delete from ArticleRule where  id = " + id;
            return db.ExecuteNonQuery(GetConntionString.conntionstring(), CommandType.Text, query);
        }

        /// <summary>
        /// 根据条件获取所有劳资规则数量
        /// </summary>
        /// <returns></returns>
        public int GetWork_ArticleRuleCount(string Condition)
        {
            sqldb db = new sqldb();
            string query = "select count(1) from ArticleRule where 1=1 " + Condition;
            object rowcount = db.ExecuteScalar(GetConntionString.conntionstring(), CommandType.Text, query);
            return Convert.ToInt32(rowcount);
        }
       
    }
}
